const LoginService = require("../service/LoginService");

const LoginController = {
  login: async (req, res) => {
    const data = req.body;
    try {
      const key = await LoginService.login(data);
      res.send({
        code: 200,
        message: "登录成功",
        data: key,
      });
    } catch (err) {
      res.status(err.status).send({
        code: err.status,
        message: err.message,
        data: err.data || null,
      });
    }
  },
  logout: async (req, res) => {
    const data = req.body;
    try {
      const key = await LoginService.logout(data);
      res.send({
        code: 200,
        message: "退出成功",
        data: key,
      });
    } catch (err) {
      res.status(err.status).send({
        code: err.status,
        message: err.message,
        data: err.data || null,
      });
    }
  },
};

module.exports = LoginController;
